﻿<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="Column" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  
  <alias>
    <typeAlias alias="Column" type="Lyh.Dbdg.Model.Column"/>
  </alias>
  
  <resultMaps>
    <resultMap id="ColumnResult" class="Column">
      <result property="Order" column="Order"/>
      <result property="Name" column="Name"/>
      <result property="DbType" column="DbType"/>
      <result property="Length" column="Length"/>
      <result property="Precision" column="Precision"/>
      <result property="Scale" column="Scale"/>
      <result property="IsNullable" column="IsNullable"/>
      <result property="DefaultValue" column="DefaultValue"/>
      <result property="Description" column="Description"/>
      <result property="IsPrimaryKey" column="IsPrimaryKey"/>
      <result property="IsIdentity" column="IsIdentity"/>
    </resultMap>
  </resultMaps>
  
  <cacheModels>
    <cacheModel id="ColumnCache" implementation="LRU">
      <flushInterval hours="24"/>
      <property name="CacheSize" value="1000"/>
    </cacheModel>
  </cacheModels>
  
  <statements>
    <select id="GetList" resultMap="ColumnResult" cacheModel="ColumnCache">
      SELECT DISTINCT c.colorder [Order],
      c.name Name,
      t.name DbType,
      c.length Length,
      c.prec Precision,
      c.xscale Scale,
      c.isnullable IsNullable,
      m.text DefaultValue,
      p.value Description,
      CASE WHEN k.id IS NULL THEN 0 ELSE 1 END IsPrimaryKey,
      CASE WHEN COLUMNPROPERTY(c.id, c.name, 'IsIdentity') = 1 THEN 1 ELSE 0 END IsIdentity
      FROM syscolumns c
      INNER JOIN sysobjects o ON c.id = o.id
      LEFT JOIN systypes t ON c.xusertype = t.xusertype
      LEFT JOIN syscomments m ON c.cdefault = m.id
      LEFT JOIN sys.extended_properties p ON c.id = p.major_id AND c.colid = p.minor_id
      LEFT JOIN sysindexkeys k ON c.id = k.id AND c.colid= k.colid
      WHERE o.name = #value#
    </select>
  </statements>
  
</sqlMap>